/** * 杂费 */
<template>
  <Card style="height:800px">
    <header>
      <span>描述:</span>
      <Input v-model="desc" style="width:200px" placeholder="请输入"></Input>
      <Button type="primary" @click="queryPage" style="margin-left: 10px;">查询</Button>
      <Button type="primary" @click="addItem();" style="margin-left: 10px;">新建</Button>
    </header>
    <Content style="margin-top:20px;">
      <Table border :columns="columns1" :data="data1"></Table>
    </Content>
    <div class="page-box">
      <Page :total="totalNumber" size="small" :current="currentPage" :page-size="pageSize" show-total @on-change="pageIndexChange"></Page>
    </div>
  </Card>
</template>

<script>
export default {
  data () {
    return {
      path: this.$route.path,

      $ajax: null,

      totalNumber: 0, // 总记录数

      currentPage: 1, // 当前页码

      pageSize: 10, // 页大小

      desc: '',

      columns1: [{
        title: 'ID',
        key: 'miscFeeId',
        align: 'center',
        width: 100,
        type: 'index'
        // render: (h, params) => {
        //   var vm = this
        //   return h('div', [
        //     h('a', {
        //       style: {
        //         textDecoration: 'underline'
        //       },
        //       on: {
        //         click: function () {
        //           vm.$router.push({
        //             path: vm.path + '/editor',
        //             query: {
        //               index: params.row.miscFeeId,
        //               type: 2
        //             }
        //           })
        //         }
        //       }
        //     }, params.row.miscFeeId)
        //   ])
        // }
      },
      {
        title: '描述',
        align: 'center',
        key: 'miscFeeName'
      },
      {
        title: '状态',
        align: 'center',
        key: 'status',
        render: function (h, param) {
          const status = param.row.status
          switch (status) {
            case 0:
              return h('div', '使用中')
            case 1:
              return h('div', '拒绝')
            case 9:
              return h('div', '待审核')
            case 10:
              return h('div', '停用')
            default:
              return h('div', '')
          }
        }
      },
      {
        title: '操作',
        align: 'center',
        width: 300,
        render: function (h, param) {
          const vm = this
          return h('div', {}, [
            (param.row.status === 9 || param.row.status === 1) && h('Button', {
              props: {
                type: 'primary',
                size: 'small'
              },
              style: {
                fontSize: '12px',
                marginLeft: '5px'
              },
              on: {

                click: () => {
                  this.$Modal.confirm({
                    title: '杂费审核',

                    content: '通过?',

                    okText: '确定',

                    cancelText: '取消',
                    onOk: () => {
                      var params = {
                        miscFeeId: param.row.miscFeeId,
                        status: 0,
                        checkDesc: true
                      }
                      vm.$ajax.post(vm.$appContext.marvels_core_product + '/product/param/miscfee/service/updateStatus', params).then(re => {
                        var data = re.data
                        var code = data.code
                        if (code === 'success') {
                          param.row.status = 0
                        }
                      }).catch(er => {

                      })
                    }
                  })
                }
              }
            }, '通过'),
            param.row.status === 9 && h('Button', {
              props: {
                type: 'primary',
                size: 'small'
              },
              style: {
                fontSize: '12px',
                marginLeft: '5px'
              },
              on: {
                click: () => {
                  this.$Modal.confirm({
                    title: '杂费审核',

                    content: '拒绝?',

                    okText: '确定',

                    cancelText: '取消',
                    onOk: () => {
                      var params = {
                        miscFeeId: param.row.miscFeeId,
                        status: 1,
                        checkDesc: true
                      }

                      vm.$ajax.post(vm.$appContext.marvels_core_product + '/product/param/miscfee/service/updateStatus', params).then(re => {
                        var data = re.data
                        var code = data.code
                        if (code === 'success') {
                          param.row.status = 1
                        }
                      }).catch(er => {

                      })
                    }
                  })
                }

              }
            }, '拒绝'),
            param.row.status === 10 && h('Button', {
              props: {
                type: 'primary',
                size: 'small'
              },
              style: {
                fontSize: '12px',
                marginLeft: '5px'
              },
              on: {
                click: () => {
                  this.$Modal.confirm({
                    title: '杂费审核',

                    content: '使用?',

                    okText: '确定',

                    cancelText: '取消',
                    onOk: () => {
                      var params = {
                        miscFeeId: param.row.miscFeeId,
                        status: 0,
                        checkDesc: true
                      }

                      vm.$ajax.post(vm.$appContext.marvels_core_product + '/product/param/miscfee/service/updateStatus', params).then(re => {
                        var data = re.data
                        var code = data.code
                        if (code === 'success') {
                          param.row.status = 0
                        }
                      }).catch(er => {

                      })
                    }
                  })
                }
              }
            }, '使用'),
            param.row.status === 0 && h('Button', {
              props: {
                type: 'primary',
                size: 'small'
              },
              style: {
                fontSize: '12px',
                marginLeft: '5px'
              },
              on: {
                click: () => {
                  this.$Modal.confirm({
                    title: '杂费审核',

                    content: '使用?',

                    okText: '确定',

                    cancelText: '取消',
                    onOk: () => {
                      var params = {
                        miscFeeId: param.row.miscFeeId,
                        status: 10,
                        checkDesc: true
                      }

                      vm.$ajax.post(vm.$appContext.marvels_core_product + '/product/param/miscfee/service/updateStatus', params).then(re => {
                        var data = re.data
                        var code = data.code
                        if (code === 'success') {
                          param.row.status = 10
                        }
                      }).catch(er => {

                      })
                    }
                  })
                }
              }
            }, '停用'),
            // param.row.status === 9 && !vm.$route.meta.isFromCheck &&
            h('Button', {
              props: {
                type: 'info',
                size: 'small'
              },
              style: {
                fontSize: '12px',
                marginLeft: '5px'
              },
              on: {
                'click' () {
                  vm.$router.push({
                    path: vm.path + '/editor',
                    query: {
                      index: param.row.miscFeeId,
                      type: 1
                    }
                  })
                }
              }

            }, ' 编辑'),
            h(
              'Button',
              {
                props: {
                  type: 'primary',
                  size: 'small'
                },
                style: {
                  fontSize: '12px',
                  marginLeft: '5px'
                },
                on: {
                  click: () => {
                    vm.$router.push({
                      path: vm.path + '/editor',
                      query: {
                        index: param.row.miscFeeId,
                        type: 2
                      }
                    })
                  }
                }
              },
              '查看'
            ),
            h(
              'Button',
              {
                props: {
                  type: 'error',
                  size: 'small'
                },
                style: {
                  fontSize: '12px',
                  marginLeft: '5px'
                },
                on: {
                  click () {
                    vm.$Modal.confirm({
                      title: '杂费',

                      content: '确定删除?',

                      okText: '确定',

                      cancelText: '取消',
                      onOk: () => {
                        var params = {
                          miscFeeId: param.row.miscFeeId
                        }
                        vm.$ajax
                          .post(
                            vm.$appContext.marvels_core_product +
                        '/product/param/miscfee/service/delete',
                            params
                          )
                          .then(re => {
                            var data = re.data
                            var code = data.code
                            var message = data.message
                            if (code === 'success') {
                              vm.$Message.success(message)
                            } else {
                              vm.$Message.warn(data.data)
                            }
                            vm.queryPage()
                          })
                      }
                    })
                  }
                }
              },
              '删除'
            )
          ])
        }.bind(this)
      }
      ],

      data1: [

      ]

    }
  },

  methods: {
    pageIndexChange (pageIndex) {
      this.currentPage = pageIndex
      this.queryPage()
    },

    initPage () {
      this.queryPage()
    },

    queryPage () {
      const vm = this
      if (vm.desc.length > 30) {
        this.$Message.warning('查询参数输入过长')
        return
      }
      var params = {
        currentPage: vm.currentPage,
        pageSize: vm.pageSize,
        desc: vm.desc
      }
      vm.$ajax.post(vm.$appContext.marvels_core_product + '/product/param/miscfee/service/list', params).then(re => {
        var data = re.data
        var code = data.code
        var message = data.message
        if (code !== 'success') {
          this.$Message.warning(message)
          return
        }
        vm.data1 = re.data.data.list
        vm.totalNumber = re.data.data.total
      }).catch(er => {

      })
    },

    addItem () {
      this.$router.push({
        name: 'misc-option-editor',
        query: {
          type: 0
        }
      })
    }
  },

  created () {
    // 初始化当前页面请求对象实例
    this.$ajax = this.$util.ajax()
    this.initPage()
  }
}
</script>

<style lang="less">
@import '../../../styles/common.less';
@import '../../../styles/table.less';
</style>
